import { ref, watchEffect } from "vue";
const tabbarPathList = ref<string[]>(sessionStorage.getItem('tabbarPathList') ? JSON.parse(sessionStorage.getItem('tabbarPathList')!) : []);
watchEffect(() => {
  sessionStorage.setItem('tabbarPathList' , JSON.stringify(tabbarPathList.value));
});
export function useTabbarPathStore () {
  const addPath = (fullPath: string) => {
    const index = tabbarPathList.value.findIndex(path => fullPath === path);
    if (index === -1) {
      tabbarPathList.value.push(fullPath);
    }
  }
  const updatePath = (fullPath: string) => {
    const index = tabbarPathList.value.findIndex(path => fullPath === path);
    tabbarPathList.value.splice(index , 1);
    tabbarPathList.value.push(fullPath);
  }
  const closePath = (fullPath: string) => {
    const index = tabbarPathList.value.findIndex(path => fullPath === path);
    if (index > -1) {
      tabbarPathList.value.splice(index , 1);
    }
  }
  const hasPath = (fullPath: string) => {
    return tabbarPathList.value.includes(fullPath);
  }
  return {
    tabbarPathList,
    addPath,
    updatePath,
    closePath,
    hasPath
  }
}